module DeclarationsHelper

  def observe_amount_fields
    observe_field 'declaration_round_amount', {
      :update => "participants", 
      :url => { :controller => 'ajax', 
      :action => 'add_user_to_declaration'},
      :submit => 'declaration_form'
    }
  
    observe_field 'declaration_decimal_amount', {
      :update => "participants", 
      :url => { :controller => 'ajax', 
      :action => 'add_user_to_declaration'},
      :submit => 'declaration_form'
    }
  end
  
  def all_users(declaration)
    declaration.declaration_payers.map { |dp|
      text = dp.user.firstname
      
      if dp.additional_persons.to_i == 1
        text += " (1 persoon extra)"
      elsif dp.additional_persons.to_i > 1
        text += " (#{dp.additional_persons} personen extra)"
      end
      text
      }.join(", ")
  end
  
end